<template>
  <div id="character-story" :class="{ h5: this.$store.state.webType === 'h5' }">
    <el-row :span="24" class="page">
      <!-- 面包屑 -->
      <el-breadcrumb separator-class="el-icon-arrow-right">
        <el-breadcrumb-item :to="{ path: '/' }">{{ $t("home") }} </el-breadcrumb-item>
        <el-breadcrumb-item>{{ $t("sections") }}</el-breadcrumb-item>
        <el-breadcrumb-item>{{ $t("people") }}</el-breadcrumb-item>
      </el-breadcrumb>
      <!--      :style="{'background-image': bannerData[currentIndex].imgUrl}"-->
      <div class="banner-view">
        <div class="banner_bg_box">
          <div class="close_banner_bg_box"><i class="el-icon-close"></i></div>
          <div class="banner_bg_left">
            <h2>{{ artData[0].module }}</h2>
            <div>
              <!-- Over 2020 over four thousand clubs,center and association for unelll,Over 2020 over
              four thousand clubs,center and association for unelll,Over 2020 over four thousand
              clubs,center and association for unelll,Over 2020 over four thousand clubs,center and
              association for unelll. -->
              {{ artData[0].brief }}
            </div>
          </div>
          <div class="banner_bg_right">
            <!-- <div class="bg_right_item" @click="clickItemBox">
              <img
                src="https://lanhu-dds-backend.oss-cn-beijing.aliyuncs.com/merge_image/imgs/bd0499dc583d407ea9036c689b1bbe56_mergeImage.png"
              />
              <div>Title is header</div>
              <div class="item_more_btn" @click="goGovern">More<i class="el-icon-right"></i></div>
            </div>
            <div class="bg_right_item">
              <img
                src="https://lanhu-dds-backend.oss-cn-beijing.aliyuncs.com/merge_image/imgs/b3f59d5e83c744858d3e3bce21775129_mergeImage.png"
              />
              <div>Title is header</div>
            </div> -->
            <div v-for="(item, ind) in artData.slice(1)" :key="ind">
              <div class="bg_right_item" @click="clickItemBox(item, ind)">
                <img :src="item.coverImage" height="250px" />
                <div>{{ item.module }}</div>
                <div class="item_more_btn" @click="goGovern(item)">
                  More<i class="el-icon-right"></i>
                </div>
              </div>
            </div>
          </div>
        </div>
        <!-- <el-carousel trigger="click" :arrow="'always'"
                     :initial-index="currentIndex"
                     indicator-position="outside"
                     :height="bannerHeight + 'px'">
          <el-carousel-item v-for="(item, index) in bannerData" :key="index">
            <div class="banner-item"
                 @click="$goDetail(item.id)"
                 :style="{height: '100%',background: `url('${item.imgUrl}') no-repeat  center`, backgroundSize: 'contain'}">
              <div class="item-title" @click="$goDetail(item.id)">
                {{ item.title }}
              </div>
            </div>
          </el-carousel-item>
        </el-carousel> -->
      </div>
    </el-row>
  </div>
</template>

<script>
import goTop from "../components/goTop";
import HotArticle from "@/components/HotArticle";
import NewBook from "@/components/NewBook";
import image from "element-ui/packages/image";

export default {
  name: "CharacterStory",
  computed: {
    image() {
      return image;
    },
  },
  components: {
    goTop,
    HotArticle,
    NewBook,
  },
  data() {
    return {
      busy: true,
      nomore: false,
      gutterWidth: 20,

      bannerHeight: 0, // 轮播图容器高度;
      // 左侧大图
      bigBanner: {},
      // banner数据
      bannerData: [],
      // 当前展示的banner index
      currentIndex: 0,
      // {{$t('latest')}}
      bookData: {},
      // 热点文章
      articleData: [],
      // 当前文章列表展示形式
      currentView: "img",
      // 文章列表
      artData: [],
      // 文章总数量
      listTotal: 0,
      maxPage: 1,
      // 文章列表请求信息
      listQuery: {
        // columnId: "",
        // labelId: "",
        pageSize: 10,
        pageNum: 1,
      },
      // 标签
      labelData: [],
      currentLabel: "",
    };
  },
  mounted() {
    this.screenWidth = window.innerWidth;
    this.bannerHeight = (730 / 1920) * this.screenWidth;
    console.log("bannerHeight", this.bannerHeight);
    if (this.$store.state.webType === "h5") {
      this.bannerHeight += 42;
    }
    // 窗口大小发生改变
    window.onresize = () => {
      this.screenWidth = window.innerWidth;
      this.bannerHeight = (730 / 1920) * this.screenWidth;
      if (this.$store.state.webType === "h5") {
        this.bannerHeight += 42;
      }
    };
    if (this.$route.query.token) {
      sessionStorage.setItem("token", this.$route.query.token);
    }
    // this.listQuery.columnId = this.$getPartId(this.$route.path);
    // this.listQuery.menuId = this.$getMenuId(this.$route.path);
    this.getList();
    // this.getBanner();
    // this.getLabels();
  },
  methods: {
    goGovern(item) {
      // this.$router.push("/governanceDetail");
      this.$router.push({
        path: "/governanceDetail",
        query: {
          id: item.gId,
        },
      });
    },
    animateHeight(element, targetHeight) {
      let startHeight = element.offsetHeight;
      const step = ((startHeight) => {
        return () => {
          if (startHeight < targetHeight) {
            startHeight += (targetHeight - startHeight) / 20;
            element.style.height = `${startHeight}px`;
            window.requestAnimationFrame(step);
          }
        };
      })(startHeight);

      // 触发动画
      window.requestAnimationFrame(step);
    },
    clickItemBox(item, ind) {
      let domItem = document.getElementsByClassName("bg_right_item")[ind];
      let btnDomMore = document.getElementsByClassName("item_more_btn")[ind];
      domItem.addEventListener("click", () => {
        this.animateHeight(domItem, 400);
        btnDomMore.style.display = "block";
      });
    },
    async loadMore() {
      // console.log(
      //   "loadMore",
      //   this.busy || this.listQuery.pageNum >= this.maxPage
      // );
      if (this.busy || this.listQuery.pageNum >= this.maxPage) return;
      this.busy = true;
      this.listQuery.pageNum += 1;
      await this.getList();
    },
    async getList() {
      this.$get(this.$api + "/un/web/governance", {}).then((res) => {
        this.artData = res.data;
      });
    },
    changeLabel(id, label) {
      this.listQuery.labelId = id;
      this.listQuery.pageNum = 1;
      this.currentLabel = label;
      this.artData = [];
      this.getList();
    },
    getLabels() {
      this.$get(this.$api + "/cms/web/getLabelByPartId", {
        partId: this.listQuery.columnId,
      }).then((res) => {
        this.labelData = res.data;
      });
    },
    getListMore() {
      this.listQuery.pageNum += 1;
      this.getList();
    },
    getBanner() {
      this.$get(this.$api + "/cms/web/partArticleBanner", {
        menuId: this.listQuery.menuId,
      }).then((res) => {
        this.bannerData = res.data;
        console.log("bannerData", this.bannerData);
        // res.data.forEach((item, index) => {
        //   if (index === 0) {
        //     this.bigBanner = item;
        //   } else {
        //     this.bannerData.push(item);
        //   }
        // });
        //  console.log(res, this.bigBanner, this.bannerData);
      });
    },
    viewTypeChange(type) {
      this.artData = [];
      this.listQuery.pageNum = 1;
      this.getList();
      this.currentView = type;
      this.$nextTick(() => {
        this.$redrawVueMasonry();
      });
    },
  },
};
</script>
<style lang="scss">
.en #character-story .banner-view .content-html p,
.en #character-story .banner-view .content-html article {
  font-family: "Times New Roman", Times, serif !important;
  font-size: fh(16vh, pc);
}
</style>
<style lang="scss" scoped>
#character-story {
  position: relative;
  width: 100%;
  background-color: rgba(15, 0, 0, 0.5);

  &::after {
    content: "";
    position: absolute;
    left: 0;
    top: 0;
    z-index: -1;
    width: 100%;
    height: 100%;
  }

  .page {
    padding: fh(152vh, pc) fw(80vw, pc) fh(40vh, pc) fw(80vw, pc);
    background: #fff;

    ::v-deep .el-breadcrumb {
      // margin-left: fw(-40vw, pc);
      .el-breadcrumb__inner {
        font-weight: bold;
        color: #fff !important;
        font-size: fh(18vh, pc);
      }
    }
  }

  .art-row {
    display: flex;
    padding-top: fh(28vh, pc);
    width: 100%;
  }

  .art-col {
    position: relative;
    width: fw(1180vw, pc);
    margin-top: fh(20vh, pc);

    .art-tab {
      width: 100%;
      display: flex;
      align-items: center;
      margin-bottom: fh(30vh, pc);
      color: $sh;

      .tab-item {
        margin-right: fw(60vw, pc);
        font-size: fh(16vh, pc);
        position: relative;
        line-height: fh(24vh, pc);

        &:hover {
          color: $sh;
          cursor: pointer;
        }

        &.active {
          font-size: fh(20vh, pc);
          font-weight: bold;
          color: $sh;

          &::before {
            content: "";
            position: absolute;
            bottom: fh(-14vh, pc);
            width: 100%;
            border-top: fh(6vh, pc) solid $zh;
          }
        }
      }

      .tab-info {
        margin-left: auto;
        display: flex;
        align-items: center;

        .toggle-img {
          margin-left: fh(62vw, pc);
          margin-right: fh(24vw, pc);
        }

        img {
          width: fw(20vw, pc);
          cursor: pointer;
        }
      }
    }

    .art-view {
      cursor: pointer;

      &.text {
        .art-item {
          width: 100%;
        }

        .item-title {
          color: $sh;
          display: flex;
          width: 100%;

          .item-info {
            padding-left: fw(40vw, pc);
            margin-left: auto;
            width: max-content !important;

            .info-label {
              margin-right: fw(20vw, pc);
              width: max-content !important;
            }

            .info-time {
              width: max-content;
              margin-left: fw(20vw, pc) !important;
            }
          }
        }
      }

      .art-item {
        // break-inside: avoid;
        width: calc((100% - 40px) / 3);
        margin-bottom: fh(20vh, pc);
        background-color: $dh;

        &:hover {
          opacity: 0.9;
        }

        cursor: pointer;

        img {
          width: 100%;
        }

        .art-content {
          width: 100%;
          color: $sh;
          padding: fh(20vh, pc) fw(20vw, pc);
          position: relative;
          z-index: 2;
          background-color: $dh;

          .item-title {
            color: $sh;
            line-height: 130%;
            height: fh(40vh, pc);
            font-size: fh(16vh, pc);
            margin-bottom: fh(8vh, pc);
            font-weight: 600;
          }

          .item-info {
            display: flex;
            align-items: center;
            width: 100%;
            justify-content: space-between;
            margin-bottom: fh(0vh, pc);
            font-size: fh(14vh, pc);
            line-height: fh(20vh, pc);

            .info-time {
              color: #a1b8bd;
              margin-left: auto;
            }
          }

          .item-content {
            font-size: fh(14vh, pc);
            line-height: fh(20vh, pc);
            font-weight: 400;
            width: 100%;
            overflow: hidden;
            text-overflow: ellipsis;
            white-space: nowrap;
          }
        }
      }
    }

    .art-more {
      width: max-content;
      margin: fh(40vh, pc) auto;
      color: $sh;
      font-size: fh(14vh, pc);

      &.true:hover {
        cursor: pointer;
        opacity: 0.8;
        color: $zh;
      }

      &.none {
        opacity: 0.5;
      }
    }
  }

  .row-right {
    flex: 1;
    margin-left: fw(20vw, pc);
  }
  @keyframes grow {
    from {
      height: 0;
    }
    to {
      height: 600px;
    } /* 假设我们想让元素的高度增加到100px */
  }
  @keyframes growItem {
    from {
      height: 0;
    }
    to {
      height: 317px;
    } /* 假设我们想让元素的高度增加到100px */
  }
  @keyframes growImg {
    from {
      width: 0;
    }
    to {
      width: 100%;
    } /* 假设我们想让元素的高度增加到100px */
  }

  .banner-view {
    width: 100vw;

    margin-bottom: fh(30vh, pc);
    position: relative;
    left: fw(-80vw, pc);
    background-size: 100% auto;
    background-repeat: no-repeat;
    background-position: center 0;
    .banner_bg_box {
      background: rgba(74, 146, 236, 1);
      animation: grow 2s; /* 2秒完成动画，无限次数 */
      height: 600px;
      animation-timing-function: ease-in-out; /* 缓进缓出效果 */
      padding-top: 60px;
      display: flex;
      .close_banner_bg_box {
        position: absolute;
        top: 17px;
        right: 27px;
        color: #fff;
        font-size: 23px;
      }
      .banner_bg_left {
        margin-left: 10%;
        width: 262px;
        color: rgba(255, 255, 255, 1);
        h2 {
          overflow-wrap: break-word;
          color: rgba(255, 255, 255, 1);
          font-size: 24px;
          font-family: "SourceHanSansCN-Bold";
          font-weight: 700;
          text-align: left;
          white-space: nowrap;
          line-height: 36px;
          margin-bottom: 15px;
        }
        div {
          overflow-wrap: break-word;
          color: rgba(255, 255, 255, 1);
          font-size: 14px;
          font-family: "SourceHanSansCN-Regular";
          font-weight: normal;
          text-align: left;
          line-height: 22px;
        }
      }
      .banner_bg_right {
        width: 54%;
        height: 60px;
        display: flex;
        justify-content: space-around;
        .bg_right_item {
          background: #fff;
          animation: growItem 2s; /* 2秒完成动画，无限次数 */
          animation-timing-function: ease-in-out; /* 缓进缓出效果 */
          height: 317px;
          width: 200px;
          border-radius: 12px;
          img {
            animation: growImg 2s; /* 2秒完成动画，无限次数 */
            animation-timing-function: ease-in-out; /* 缓进缓出效果 */
            width: 100%;
          }
          div {
            overflow-wrap: break-word;
            color: rgba(74, 146, 236, 1);
            font-size: 16px;
            font-family: "SourceHanSansCN-Regular";
            font-weight: normal;
            text-align: left;
            white-space: nowrap;
            line-height: 24px;
            text-align: center;
            margin-top: 12px;
          }
          div:nth-child(3) {
            background-color: rgba(74, 146, 236, 1);
            border-radius: 21px;
            width: 144px;
            height: 40px;
            line-height: 40px;
            margin-top: 30px;
            color: #fff;
            display: flex;
            justify-content: center;
            align-items: center;
            margin-left: 20px;
            display: none;
          }
        }
      }
    }

    .banner-item {
      cursor: pointer;
    }

    ::v-deep .el-carousel {
      width: 100%;
      position: static;
      background-color: #f1f4f5;
      .el-carousel__arrow {
        background-color: rgba(255, 255, 255, 0);
        i {
          color: #0046b4;
          font-size: 40px;
        }
      }
      .el-carousel__indicators--horizontal {
        position: absolute;
        bottom: fh(-40vh, pc);

        //.#A1B8BD
        .el-carousel__button {
          background-color: #0046b4;
          width: 40px;
          height: 4px;
          border-radius: 2px;
        }
      }
    }

    .item-title {
      width: 100%;
      // height: fh(68vh, pc);
      padding: 16px;
      text-align: center;
      position: absolute;
      left: 0;
      bottom: 0;
      color: $zh;
      font-weight: bold;
      font-size: fh(24vh, pc);
      line-height: fh(36vh, pc);
      background: rgba(0, 0, 0, 0.3);
      color: #fff;
      cursor: pointer;

      &:hover {
        opacity: 0.8;
      }
    }

    .item-content {
      flex: 1;
      padding: fw(20vw, pc);

      .more {
        position: absolute;
        bottom: fw(20vw, pc);
        right: fw(20vw, pc);
        font-size: fh(14vh, pc);
        font-weight: 600;
        color: #686a67;
        line-height: fh(20vh, pc);
        cursor: pointer;

        &:hover {
          opacity: 0.8;
        }
      }
    }

    ::v-deep .content-html {
      word-wrap: break-word;
      overflow: hidden;
      height: fh(288vh, pc);
      color: $sh !important;

      strong {
        color: $sh;
      }

      p,
      article,
      section {
        font-size: fh(14vh, pc);
        font-family: "宋体", "songti", "宋体-简", "serif", "sans-serif", "cursive", "fantasy",
          "monospace";
        font-weight: 400;
        color: $sh;
        line-height: fh(24vh, pc) !important;
        margin-top: fh(24vh, pc) !important;
      }

      img,
      img + p,
      img + font,
      p font {
        max-width: 100%;
        display: none;
      }

      strong {
        background-color: rgba(255, 255, 255, 0) !important;
      }

      .html-title {
        font-size: fh(16vh, pc);
        font-weight: bold;
        color: #ffffff;
        line-height: fh(24vh, pc);
      }
    }

    .two-col {
      display: flex;
      align-items: flex-start;
      flex-wrap: wrap;
      flex: 1;
      justify-content: space-between;

      .two-item {
        height: fh(280vh, pc);
        position: relative;
        width: 100%;
        display: flex;
        align-content: flex-start;
        background-color: #f6f6f6;

        &:nth-last-child(1) {
          margin-top: fh(40vh, pc);
        }

        .scale-view {
          width: fw(350vw, pc);
        }

        img {
          width: fw(350vw, pc);
          display: block;
          height: 100%;
        }
      }
    }
  }
}

#character-story.h5 {
  .row-right {
    margin-left: 0;
  }

  .art-col {
    margin-top: 0;

    .art-view {
      &.text {
        .art-item {
          width: 100%;
        }
      }

      .art-item {
        width: calc(50% - 10px);
        margin-bottom: fw(8vw, h5);

        .art-content {
          padding: fw(8vw, h5) !important;
        }
      }
    }
  }

  .banner-view {
    flex-wrap: wrap;
    .item-title {
      padding: 4px;
      font-size: 16px;
      line-height: 22px;
    }
    ::v-deep .el-carousel__indicators--horizontal {
      left: 50%;
      transform: translateX(-50%);
      .el-carousel__button {
        width: 28px;
        height: 2px;
        bottom: -10px;
      }
    }
    .banner-col {
      width: 100%;
      margin-bottom: fh(5vh, h5);
      flex-wrap: wrap;
      height: auto !important;

      > div {
        width: 100%;
      }

      .item-content {
        padding: fh(20vh, h5) fw(10vw, h5);
        padding-bottom: fh(40vh, h5);

        .more {
          bottom: fh(12vh, h5);
          right: fw(10vw, h5);
        }
      }

      .banner-big {
        width: 100%;
        height: auto !important;
      }
    }

    .two-col {
      width: 100%;

      .two-item {
        width: 49%;
        margin-bottom: fh(5vh, h5);

        .item-title {
          color: $sh;
          width: 100%;
          padding: fw(4vw, h5) fw(4vw, h5) !important;
          height: max-content;
          line-height: fh(20vh, h5);
          font-size: fh(14vh, h5);
        }
      }
    }
  }
}
</style>
